package com.android.launcher3.widget;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.android.launcher3.AppInfo;
import com.android.launcher3.R;

public class HotSeatAppWidget extends FrameLayout {

    private View container;
    private View add;
    private ImageView image;
    private AppInfo appInfo;

    public HotSeatAppWidget(@NonNull Context context) {
        super(context);
        init();
    }

    public HotSeatAppWidget(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public HotSeatAppWidget(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.layout_hot_seat_app, this, true);
        container = findViewById(R.id.container);
        add = findViewById(R.id.v_add);
        image = findViewById(R.id.image);
    }

    public void setAppInfo(@Nullable AppInfo appInfo) {
        this.appInfo = appInfo;
        if (appInfo == null) {
            add.setVisibility(VISIBLE);
            image.setVisibility(GONE);
            container.setBackgroundResource(R.drawable.bg_small_corners);

        } else {
            add.setVisibility(GONE);
            image.setVisibility(VISIBLE);
            if (appInfo.iconBitmap != null) {
                image.setImageBitmap(appInfo.iconBitmap);
            }
            container.setBackground(new ColorDrawable(Color.TRANSPARENT));
        }
    }

    @Nullable
    public AppInfo getAppInfo() {
        return appInfo;
    }


}
